<template>
  <div>
    <el-form ref="ruleForm" :model="ruleForm" status-icon label-width="100px" class="demo-ruleForm">
      <el-row>
        <!-- <el-col :xs="8" :sm="6" :md="4" :lg="3" :xl="1"><div class="grid-content bg-purple" /></el-col> -->
        <el-col :span="12">
          <el-form-item
            prop="mobile"
            label="电话号码"
          >
            <el-input v-model="ruleForm.mobile" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-form-item
          label="入职时间"
        >
          <el-date-picker v-model="ruleForm.correctionTime" type="date" placeholder="选择日期" />
        </el-form-item>
      </el-row>
      <el-form-item label="图片">
        <!-- <img :src="ruleForm.staffPhoto" alt="图片没有显示出来的替代文字" title="鼠标移动上去显示的文字"> -->
        <UploadImg :key="ruleForm.id" :src.sync="ruleForm.staffPhoto" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
        <el-button>返回</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { getUserInfoRequest, updateUserInfoRequest } from '@/api/employees'

export default {
  name: 'VueHr85Userdetail',

  data() {
    return {
      ruleForm: {
        mobile: '',
        correctionTime: ''
      }
    }
  }, created() {
    this.getUserInfo()
  },
  methods: {
    async updateUserInfo() {
      try {
        const res = await updateUserInfoRequest(this.ruleForm)
        if (res.success) {
          this.$message.success('更新用户信息成功')
          this.$router.back()
        } else {
          this.$message.error('更新用户信息失败')
        }
      } catch (error) {
        console.log('updateUserInfoRequest', error)
      }
    },
    async getUserInfo() {
      try {
        const res = await getUserInfoRequest(this.$route.query?.id || '')
        console.log(res)
        this.ruleForm = res.data
        console.log('getUserInfoRequest', res)
      } catch (error) {
        console.log('getUserInfoRequest', error)
      }
    },
    submitForm() {
      this.$refs.ruleForm.validate((val) => {
        if (val) {
          console.log(this.ruleForm)
          this.updateUserInfo()
        }
      })
    }

  }
}
</script>

<style lang="scss" scoped>

</style>
